package com.thoughtworks;
import java.util.Random;
import java.util.Scanner;
import java.util.ArrayList;

public class CardMachine {
    Scanner sc = new Scanner(System.in);
    Random rd = new Random();

    public ArrayList<Card> createCards(){
        ArrayList<Card> list = new ArrayList<>();
        for(Card.Color c: Card.Color.values()){
            for(int i=0;i<13;i++){
                Card card = new Card(c.toString(), i);
                list.add(card);
            }
        }
        return list;
    }

    public void drawCard(ArrayList<Card> cardLists){
        System.out.println("Please enter how many cards (n) you want to draw: ");
        int n = sc.nextInt();
        if(n<0||n>52){
            System.out.println("n must be less than 52 and larger than 0!");
            return;
        }
        StringBuilder output = new StringBuilder();
        for(int i=0;i<n;i++){
            int nr = rd.nextInt(cardLists.size());
            String cardName = getCardName(cardLists.get(nr));
            output.append(cardName);
            cardLists.remove(nr);
        }
        System.out.println(output);
    }

    public String getCardName(Card card){
        String cardColor = card.color;
        String cardNumber = String.valueOf(card.number);
        if(card.number==1){cardNumber="A";}
        if(card.number==11){cardNumber="J";}
        if(card.number==12){cardNumber="Q";}
        if(card.number==13){cardNumber="K";}
        return cardColor+cardNumber+" ";
    }
}
